export const mergeStatementDetail = (statementDetails : []) => {
	const result = [];
	const map = new Map();

	statementDetails.forEach((dish : any) => {
		const key = `${dish.name}|${dish.amount}`;
		if (map.has(key)) {
			map.get(key).number += dish.number;
		} else {
			map.set(key, { ...dish });
		}
	});

	map.forEach(value => {
		result.push(value);
	});

	return result;
}

// 格式化日期
export const formatDate = (date : Date, withTime = false) => {
	if (!date) return '未知';
	const year = date.getFullYear();
	const month = (date.getMonth() + 1).toString().padStart(2, '0');
	const day = date.getDate().toString().padStart(2, '0');

	if (withTime) {
		const hours = date.getHours().toString().padStart(2, '0');
		const minutes = date.getMinutes().toString().padStart(2, '0');
		return `${year}-${month}-${day} ${hours}:${minutes}`;
	}

	return `${year}-${month}-${day}`;
};